package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Cabinet;
import com.share.device.service.ICabinetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author YC
 */
@Tag(name = "充电宝柜机接口管理")
@RestController
@RequestMapping("/cabinet")
public class CabinetController extends BaseController {

    @Autowired
    private ICabinetService cabinetService;

    @Operation(summary = "搜索未使用柜机")
    @GetMapping(value = "/searchNoUseList/{cabinetNo}")
    public AjaxResult searchNoUseList(@PathVariable String cabinetNo) {
        return success(cabinetService.searchNoUseList(cabinetNo));
    }

    @Operation(summary = "删除充电宝柜机")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestBody List<Long> ids) {
        boolean flag = cabinetService.removeBatchByIds(ids);
        return toAjax(flag);
    }

    @Operation(summary = "修改充电宝柜机")
    @PutMapping("/modify")
    public AjaxResult modify(@RequestBody Cabinet cabinet) {
        boolean flag = cabinetService.updateById(cabinet);
        return toAjax(flag);
    }

    @Operation(summary = "新增充电宝柜机")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Cabinet cabinet) {
        boolean flag = cabinetService.save(cabinet);
        return toAjax(flag);
    }

    @Operation(summary = "根据id查询充电宝柜机详情")
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        Cabinet cabinet = cabinetService.getById(id);
        return success(cabinet);
    }

    @Operation(summary = "分页查询充电宝柜机集合")
    @PostMapping("/page")
    public TableDataInfo page(@RequestBody Cabinet cabinet) {
        //设置分页参数
        startPage();
        //调用service方法
        List<Cabinet> list = cabinetService.selectListCabinet(cabinet);
        return getDataTable(list);
    }

}